package com.reform.controller.phase;


import com.reform.pojo.phase.BatchInfo;
import com.reform.res.Result;
import com.reform.service.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.sql.SQLException;

@Api(tags = "BatchInfoController")
@RestController
@RequestMapping("/BatchInfo")
public class BatchInfoController {
    @Autowired
    IViewBatchService viewBatchService;

    @ApiOperation(value = "获取全部批次信息", notes = "获取全部批次信息")
    @GetMapping("/getAllBatch")
    public Result getAllBatch() {
        return viewBatchService.getAllBatchInfo();
    }

    @ApiOperation(value = "根据专家工号获取批次信息", notes = "获取全部批次信息")
    @PostMapping("/getBatchIdByGH")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "gh", value = "专家工号", paramType = "query", dataTypeClass = String.class, required = true),
    })
    public Result getBatchIdByGH(String gh) throws SQLException {
        return viewBatchService.getBatchIdByGH(gh);
    }

    @ApiOperation(value = "根据batchId获取全部批次信息", notes = "根据batchId获取全部批次信息")
    @PostMapping("/getAllBatchById")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "batchId", value = "批次id", paramType = "query", dataTypeClass = String.class, required = true),
    })
    public Result getAllBatchById(String batchId) {
        return viewBatchService.getAllBatchById(batchId);
    }

    @ApiOperation(value = "通过部门id获取已授权批次信息", notes = "通过部门id获取已授权批次信息")
    @PostMapping("/getBatchByDepId")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "depId", value = "批次id", paramType = "query", dataTypeClass = Integer.class, required = true),
    })
    public Result getBatchByDepId(int depId) {
        return viewBatchService.getBatchByDepId(depId);
    }

    @ApiOperation(value = "修改批次", notes = "修改批次")
    @PostMapping("/updateBatch")
    @ApiImplicitParams({
    })
    public Result updateBatch(BatchInfo batchInfo) throws SQLException {
        return viewBatchService.updateBatch(batchInfo);
    }

    @ApiOperation(value = "删除批次", notes = "删除批次")
    @PostMapping("/deleteBatch")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "batch_id", value = "批次id", paramType = "query", dataTypeClass = String.class, required = true),
    })
    public Result deleteBatch(String batch_id) throws SQLException {
        return viewBatchService.deleteBatch(batch_id);
    }


    @ApiOperation(value = "创建批次", notes = "创建批次")
    @PostMapping("/creatBatch")
    @ApiImplicitParams({
    })
    public Result creatBatch(BatchInfo batchInfo) throws SQLException {
        return viewBatchService.creatBatch(batchInfo);
    }

    @ApiOperation(value = "查询该批次下所有项目的类别信息", notes = "查询该批次下项目的类别信息")
    @PostMapping("/selectClassificationByBatchId")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "batch_id", value = "批次id", paramType = "query", dataTypeClass = String.class, required = true),
    })
    public Result selectClassificationByBatchId(String batch_id) throws SQLException {
        return viewBatchService.selectClassificationByBatchId(batch_id);
    }

    @ApiOperation(value = "查询批次下最大参与数", notes = "查询批次下最大参与数")
    @PostMapping("/selectMaxParticipants")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "batch_id", value = "批次id", paramType = "query", dataTypeClass = String.class, required = true),
    })
    public Result selectMaxParticipants(String batch_id) throws SQLException {
        return viewBatchService.selectMaxParticipants(batch_id);
    }

    @ApiOperation(value = "查询批次下最大主持数", notes = "查询批次下最大主持数")
    @PostMapping("/selectMaxHost")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "batch_id", value = "批次id", paramType = "query", dataTypeClass = String.class, required = true),
    })
    public Result selectMaxHost(String batch_id) throws SQLException {
        return viewBatchService.selectMaxHost(batch_id);
    }

    @ApiOperation(value = "获取批次id和名称", notes = "获取批次id和名称")
    @GetMapping("/getBatchName")
    public Result getBatchName() throws SQLException {
        return viewBatchService.getBatchName();
    }

    @ApiOperation(value = "获取批次信息", notes = "批次中有项目为延期，其所在阶段为结项")
    @PostMapping("/getBatchInfoIncludeDelay")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "status", value = "批次状态", paramType = "query", dataTypeClass = String.class, required = true),
    })
    public Result getBatchInfoIncludeDelay(Integer status) throws SQLException {
        return viewBatchService.getBatchInfoIncludeDelay(status);
    }

}
